<html>
<body>
<script>
// Create an iframe to receive and send storage events with.
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write('<body></body>');
iframe.contentWindow.document.close();

var listener = function(event) {
  var event_count = Number(sessionStorage.event_count);
  sessionStorage.event_count = event_count + 1;
}
iframe.contentWindow.addEventListener('storage', listener, false);
sessionStorage.event_count = 0;

// Print the number of events after 4 seconds.
setTimeout(function() {
  console.log(sessionStorage.event_count);
}, 4000);
</script>
</body>
</html>
